package com.hedl.practice.diyJava.reflex.Inherit_acquisition;

import java.io.Serializable;

public class Main {

    //使用反射获取父类的class
    public static void main(String[] args) {

        /*Class c = Integer.class;
        Class c1 = c.getSuperclass();
        System.out.println(c1);
        Class c2 = c1.getSuperclass();
        System.out.println(c2);
        System.out.println(c2.getSuperclass());*/


        Class c = Integer.class.getSuperclass();
        System.out.println(c);
        Class[] c3 = c.getInterfaces();
        for (Class aClass : c3) {
            System.out.println(aClass);
        }

        System.out.println(java.io.DataInputStream.class.getSuperclass());
        System.out.println(java.io.Closeable.class.getSuperclass());

        //当我们判断一个实例是否是某个类型时，正常情况下，使用instanceof操作符：
        System.out.println("-------------------");

        Object n = Integer.valueOf(123);
        boolean isDouble = n instanceof Double;
        System.out.println(isDouble);
        boolean isInteger = n instanceof Integer;
        System.out.println(isInteger);
        boolean isNumber = n instanceof Number;
        System.out.println(isNumber);
        boolean isSerializable = n instanceof Serializable;
        System.out.println(isSerializable);

        //如果是两个Class实例，要判断一个向上转型是否成立，可以调用isAssignableFrom()：
        System.out.println("----------------");
        System.out.println(Integer.class.isAssignableFrom(Integer.class));
        System.out.println(Number.class.isAssignableFrom(Integer.class));
        System.out.println(Object.class.isAssignableFrom(Integer.class));
        System.out.println(Integer.class.isAssignableFrom(Number.class));

    }
}
